package com.gw2.gw2world.model;

import java.io.Serializable;
import java.util.Comparator;

public class Event implements Comparable<Event>, Serializable {
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + map_id;
		result = prime * result + server_id;
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Event other = (Event) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (map_id != other.map_id)
			return false;
		if (server_id != other.server_id)
			return false;
		return true;
	}
	private static final long serialVersionUID = 1L;
	/** Event ID */
	public String id="";
	/** Event name */
	public String name="";
	/** True if the event is enabled, false if disabled by user. ONLY USED FOR ACTIVE EVENTS. */
	public boolean enabled=true;
	/** Map id */
	public int map_id=0;
	/** Server id */
	public int server_id=0;
	/** Event level: 1 is the final event, higher are pre-events */
	public int depth=1;
	public int level=1;
	public int master=0;
	public int flag=0;
	/** Event state provided by API */
	public String state="Inactive";
	/** If it is a group event */
	public boolean group=false;
	public boolean living_world=false;
	public boolean bugged=false;
	public boolean isActive() {
		return state.equals("Active") /*|| state.equals("Preparation") || state.equals("Warmup")*/;
	}
	public boolean isStrictlyActive() {
		return state.equals("Active");
	}
	//Default: compare by level
	@Override
	public int compareTo(Event e) {
		return level-e.level;
	}
	public static final Comparator<Event> SORT_BY_LEVEL = new Comparator<Event>() {
		public int compare(Event e1, Event e2) {
			return e1.compareTo(e2); //asc
			//return e2.compareTo(e1); //desc
		}
	};
	public static final Comparator<Event> SORT_BY_MAP = new Comparator<Event>() {
		public int compare(Event e1, Event e2) {
			return e1.map_id>e2.map_id?0:1;
		}
	};
	public static final Comparator<Event> SORT_BY_DEPTH = new Comparator<Event>() {
		public int compare(Event e1, Event e2) {
			return e1.depth>e2.depth?0:1;
		}
	};

	@Override
	public String toString() {
		return "Event [id=" + id + ", name=" + name + ", state=" + state + "]";
	}
}
